#coding=utf8
__author__ = 'joey'

from trees import *

# 1 测试收集数据
dataSet, labels = createDataSet()
print dataSet
print labels

# 2 测试准备数据
# 2.1 测试计算香农熵, 熵越大，变量的不确定性就越大，需要把它搞清楚所需要的信息量也就越大
shannonEnt = calcShannonEnt(dataSet)
print shannonEnt

# 2.2 测试按照给定特征划分数据
data1 = splitDataSet(dataSet, 1, 1)
data2 = splitDataSet(dataSet, 1, 0)

print data1
print data2

print calcShannonEnt(data1)
print calcShannonEnt(data2)
print (len(data1) / float(len(dataSet))) * calcShannonEnt(data1)
print (len(data2) / float(len(dataSet))) * calcShannonEnt(data2)


data3 = [[1, 'yes'], [1, 'yes'], [0, 'no'], [0, 'no'], [1, 'no']]
print calcShannonEnt(data3)